<?php

if(count($argv)!=3){
	echo "Usage: DUMP | svnfilter.php \"FILENAME_PATTERN\" \"CONTENT_PATTERN\"\N";
	die;
}

#Check that patterns are valid
if(preg_match($argv[1],"")===FALSE){
	echo "Invalid filename pattern";
	exit(1);
}
if(preg_match($argv[2],"")===FALSE){
	echo "Invalid content pattern";
	exit(2);
}


$current_path = "NONE";
$revision = "N";
while($line = fgets(STDIN)){

	if(strpos($line,"Revision-number:")!==FALSE){
		$revision = trim(str_replace("Revision-number:","",$line));
		continue;
	}
	if(strpos($line,"Node-path:")!==FALSE){
		$current_path = trim(str_replace("Node-path:","",$line));
		continue;
	}

	if(preg_match($argv[2],$line)){
		if(preg_match($argv[1],$current_path)){
			echo "$revision: $current_path: $line";
		}
	}

}
?>
